﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NLBS.Control;
using NLBS;
using NLBS.Data;
using NLBS.Data.Business;
using NLBS.Web;

namespace NLBS
{
    public partial class gbook : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DeleteGuestBook();
                BindData();
                
            }
        }

        private void DeleteGuestBook()
        {
            if (RequestWrapper.GetQueryString("act") == "delete")
            {
                int id =RequestWrapper.GetQueryInt("id");
                GuestBookData.DeleteGuestBook(id);
            }
        }

        void BindData()
        {
            if (RequestWrapper.GetQueryString("act") != null)
            {
                string act = RequestWrapper.GetQueryString("act").ToString();
                if (act == "edit")
                {
                    commentForm msg = (commentForm)LoadControl("Control/commentForm.ascx");
                    msg.Action = MessageType.GusetBook;
                    guestbook1.Visible = false;
                    this.Master.FindControl("mainWrapper").Visible = true;
                    this.Master.FindControl("mainWrapper").Controls.Clear();
                    this.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
                else
                {
                    MessageHelp.ShowGuestBookAction(this,guestbook1);
                }
            }
        }

        void showContent()
        {
            if (Request.QueryString["act"] != null)
            {

                message msg = (message)LoadControl("Control/message.ascx");
                string act = Request.QueryString["act"].ToString();
                if (act != "edit" && act != "new")
                {
                    guestbook1.Visible = false;
                    this.Master.FindControl("mainWrapper").Visible = true;
                    this.Master.FindControl("mainWrapper").Controls.Clear();
                }
                if (act == "save")
                {
                    msg.SuccessContent = "新增留言成功";
                    msg.NextUrl = "gbook.aspx";
                    this.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
                else if (act == "update")
                {
                    msg.SuccessContent = "回复留言成功";
                    msg.NextUrl = "gbook.aspx";
                    this.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
                else if (act == "delete")
                {
                    msg.SuccessContent = "删除留言成功";
                    msg.NextUrl = "gbook.aspx";
                    this.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
            }
        }
    }
}
